from rest_framework import serializers

from recruits.models import Recruit, Enterprise


class AddEnterpriseVisitViewSerializers(serializers.ModelSerializer):
    '''企业访问量序列化器类'''
    id = serializers.IntegerField(label='pk')
    message = serializers.CharField(label='状态信息',default='ok',read_only=True)
    success = serializers.BooleanField(label='状态',default=True,read_only=True)

    class Meta:

        model = Enterprise

        fields = ('id','success','message')


class InnerEnterpriseViewSerializers(serializers.ModelSerializer):
    '''内层嵌套企业关联对象序列化模型类'''
    recruits = serializers.PrimaryKeyRelatedField(label='招聘',read_only=True,many=True)
    class Meta:

        model = Enterprise

        fields = ('id','name','logo','recruits','summary','labels')


class OuterRecruitsSerializers(serializers.ModelSerializer):
    '''外层嵌套招聘关联对象序列化模型类'''
    enterprise = InnerEnterpriseViewSerializers(label='企业',read_only=True)

    class Meta:

        model = Recruit

        exclude = ('address','state','visits','detailcontent','detailrequire','users')


class EnterpriseViewSerializers(serializers.ModelSerializer):
    '''企业关联对象序列化模型类'''
    recruits = OuterRecruitsSerializers(label='企业',read_only=True,many=True)

    class Meta:

        model = Enterprise

        fields = '__all__'


